package com.seabook.calparser.main;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.scheduling.timer.ScheduledTimerTask;

public class DateTimerTask extends ScheduledTimerTask {
	
	private boolean isDateDriven = false;
	
	private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	
	private String dateFormatStr ;
	

	@Override
	public long getDelay() {
		if (isDateDriven) {
			try {
				Date date = sdf.parse(dateFormatStr);
				long futureTime = date.getTime();
				long currTime = System.currentTimeMillis();
				if (futureTime - currTime >= 0) {
					return futureTime - currTime;
				}
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		
		return super.getDelay();
	}

	public boolean isDateDriven() {
		return isDateDriven;
	}

	public void setDateDriven(boolean isDateDriven) {
		this.isDateDriven = isDateDriven;
	}

	public String getDateFormatStr() {
		return dateFormatStr;
	}

	public void setDateFormatStr(String dateFormatStr) {
		this.dateFormatStr = dateFormatStr;
	}
	
	
	
}
